package ${package.Service}.impl;
<#--package ${package.Service.impl};-->
<#--package tbs.imt.data.service.impl;-->
import java.util.Optional;
import java.util.List;
import java.util.ArrayList;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.BeanUtils;
import tbs.imt.data.entity.${entity};
import tbs.imt.data.model.dto.${table.entityPath}.${entity}Dto;
import tbs.imt.data.model.vo.${table.entityPath}.${entity}ListVo;
import tbs.imt.data.model.vo.${table.entityPath}.${entity}DetailVo;
import tbs.imt.data.model.po.${table.entityPath}.${entity}CreatePo;
import tbs.imt.data.model.po.${table.entityPath}.${entity}UpdatePo;
import tbs.imt.data.model.po.${table.entityPath}.${entity}QueryPo;
import tbs.imt.data.model.po.${table.entityPath}.${entity}CreateBatchPo;
import tbs.imt.data.model.po.${table.entityPath}.${entity}UpdateBatchPo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import com.github.yulichang.base.MPJBaseService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.query.MPJQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * @author: ${author}
 * @date: ${date}
 * @description: ${table.comment!} ServiceImpl 接口
 */
@Service
@Slf4j
public class ${table.serviceImplName} extends ServiceImpl<${table.mapperName}, ${entity}> implements ${table.serviceName} {
    @Autowired
    private ${table.mapperName} ${table.entityPath}Mapper;

    @Override
    public Class<${entity}> currentModelClass() {
        return ${entity}.class;
    }

    @Override
    public IPage<${entity}ListVo> page${entity}(${entity}QueryPo po) {
        IPage<${entity}Dto> dtoIPage = selectJoinListPage(new Page<>(po.getPageIndex(), po.getPageSize()), ${entity}Dto.class, new MPJQueryWrapper<${entity}>()
            .selectAll(${entity}.class)
            .eq("t.valid",true)
            );
        return dtoIPage.convert(t->{
            ${entity}ListVo vo = new ${entity}ListVo();
            BeanUtils.copyProperties(t,vo);
            return vo;
        });
    }

    @Override
    public ${entity}DetailVo detail(String guid) {
        ${entity}DetailVo vo = new ${entity}DetailVo();
        ${entity} entity = Optional.ofNullable(getOne(new LambdaQueryWrapper<${entity}>().eq(${entity}::getValid,true).eq(${entity}::getGuid, guid).last("limit 1")))
            .orElseThrow(() -> new RuntimeException("该数据不存在"));
            BeanUtils.copyProperties(entity,vo);
            return vo;
    }

    @Override
    public void create(${entity}CreateBatchPo po) {
        List<${entity}> resList = new ArrayList<>();
        po.getCreateList().forEach(t->{
            ${entity} entity = new ${entity}();
            BeanUtils.copyProperties(t,entity);
            resList.add(entity);
        });
        saveBatch(resList);
    }

    @Override
    public void update(${entity}UpdateBatchPo po) {
        List<${entity}> resList = new ArrayList<>();
            po.getUpdateList().forEach(t->{
            ${entity} entity = new ${entity}();
            BeanUtils.copyProperties(t,entity);
            resList.add(entity);
        });
        updateBatchById(resList);
    }

    @Override
    public void delete(String guid) {
        Optional.ofNullable(getOne(new LambdaQueryWrapper<${entity}>().eq(${entity}::getValid,true).eq(${entity}::getGuid,guid).last("limit 1")))
            .orElseThrow(() -> new RuntimeException("该数据不存在"));
        LambdaUpdateWrapper<${entity}> updateWrapper = new LambdaUpdateWrapper<${entity}>().set(${entity}::getValid, false).eq(${entity}::getGuid, guid);
        update(updateWrapper);
    }

}
